package com.cnswhy.cloud.server.comsumer.consumer;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransOrderQueryRequest;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransOrderQueryResponse;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.cnswhy.cloud.common.core.exception.BizException;
import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.common.core.utils.CnswhyUtil;
import com.cnswhy.cloud.common.core.utils.Kits;
import com.cnswhy.cloud.common.core.utils.SystemClockUtil;
import com.cnswhy.cloud.common.logging.uitls.MDCUtil;
import com.cnswhy.cloud.common.rabbitmq.service.MessageService;
import com.cnswhy.cloud.server.common.entity.constant.AmqpExchange;
import com.cnswhy.cloud.server.common.entity.enumeration.SubWalletType;
import com.cnswhy.cloud.server.common.entity.enumeration.TransType;
import com.cnswhy.cloud.server.common.entity.enumeration.WalletType;
import com.cnswhy.cloud.server.common.entity.enumeration.WithdrawType;
import com.cnswhy.cloud.server.common.entity.mq.WithdrawQueryMQ;
import com.cnswhy.cloud.server.common.entity.mq.WithdrawVerifyMQ;
import com.cnswhy.cloud.server.comsumer.event.WithdrawQueryMqEvent;
import com.cnswhy.cloud.server.comsumer.event.WithdrawVerifyMqEvent;
import com.cnswhy.cloud.server.core.channel.hcpay.dto.DaifuDto;
import com.cnswhy.cloud.server.core.channel.hcpay.dto.TransQueryDto;
import com.cnswhy.cloud.server.core.channel.hcpay.dto.TransQueryResponseDto;
import com.cnswhy.cloud.server.core.channel.hcpay.service.HcpayService;
import com.cnswhy.cloud.server.core.channel.wxpay.model.WxpayServiceRp;
import com.cnswhy.cloud.server.core.channel.wxpay.service.WxpayService;
import com.cnswhy.cloud.server.core.config.AlipayConfig;
import com.cnswhy.cloud.server.core.constant.RedisConstant;
import com.cnswhy.cloud.server.core.entity.CustomerWithdrawalRecord;
import com.cnswhy.cloud.server.core.entity.SysConfig;
import com.cnswhy.cloud.server.core.entity.WithdrawalRecord;
import com.cnswhy.cloud.server.core.service.CustomerWithdrawalRecordService;
import com.cnswhy.cloud.server.core.service.SysConfigService;
import com.cnswhy.cloud.server.core.service.customer.CustomerAlipayService;
import com.cnswhy.cloud.server.core.service.customer.CustomerBankService;
import com.cnswhy.cloud.server.core.service.trans.WithdrawalRecordService;
import com.cnswhy.cloud.server.core.wallet.WalletService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class WithdrawVerifyMqConsumer implements WithdrawVerifyMqEvent, WithdrawQueryMqEvent {
    @Autowired
    WithdrawalRecordService withdrawalRecordService;
    @Autowired
    CustomerBankService customerBankService;

    @Autowired
    CustomerAlipayService customerAlipayService;
    @Autowired
    CustomerWithdrawalRecordService customerWithdrawalRecordService;
    @Autowired
    WalletService walletService;
    @Autowired
    HcpayService hcpayService;
    @Autowired
    SysConfigService sysConfigService;
    @Autowired
    MessageService messageService;
    @Autowired
    WxpayService wxpayService;
    /*@Autowired
    ChannelService channelService;*/
    private String merchId = "882030315003046";

    @Override
    public void verify(WithdrawVerifyMQ withdrawVerifyMQ) throws BizException {
        CustomerWithdrawalRecord customerWithdrawalRecord = customerWithdrawalRecordService.getById(withdrawVerifyMQ.getId());
        log.info("审核结果状态:{}", customerWithdrawalRecord.getVerifyStatus());
        if (customerWithdrawalRecord.getVerifyStatus() == 2) {
            //审核通过
            if (customerWithdrawalRecord.getWithdrawType().eq(WithdrawType.ALIPAY)) {
                SysConfig sysConfig = sysConfigService.getOne(Wraps.<SysConfig>lbQ().eq(SysConfig::getConfigKey, "alipay_df"));
                CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
                certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
                certAlipayRequest.setAppId(sysConfig.getConfigValue());
                certAlipayRequest.setPrivateKey(sysConfig.getValidateRules());
                certAlipayRequest.setFormat("json");
                certAlipayRequest.setCharset("GBK");
                certAlipayRequest.setSignType("RSA2");
                certAlipayRequest.setCertPath("/usr/local/app/appCertPublicKey_" + sysConfig.getConfigValue() + ".crt");
                certAlipayRequest.setAlipayPublicCertPath("/usr/local/app/alipayCertPublicKey_RSA2_" + sysConfig.getConfigValue() + ".crt");
                certAlipayRequest.setRootCertPath("/usr/local/app/alipayRootCert_" + sysConfig.getConfigValue() + ".crt");
                /*certAlipayRequest.setCertPath(sysConfig.getConfigRules());
                certAlipayRequest.setAlipayPublicCertPath("//home//aliCert//alipayCertPublicKey_RSA2.crt");
                certAlipayRequest.setRootCertPath("//home//aliCert//alipayRootCert.crt");*/

                AlipayClient alipayClient = null;
                try {
                    alipayClient = new DefaultAlipayClient(certAlipayRequest);
                } catch (AlipayApiException e) {
                    e.printStackTrace();
                }

                AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
                request.setBizContent("{" + "\"out_biz_no\":\"" + customerWithdrawalRecord.getOrderId() + "\"," + "\"trans_amount\":"
                        + String.format("%.2f",Double.valueOf(customerWithdrawalRecord.getTransAmount()) / 100) + "," + "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\","
                        + "\"biz_scene\":\"DIRECT_TRANSFER\"," +
                        // "\"original_order_id\":\"20190620110075000006640000063056\"," +
                        "\"payee_info\":{" + "\"identity\":\"" + customerWithdrawalRecord.getWithdrawAccount() + "\","
                        + "\"identity_type\":\"ALIPAY_LOGON_ID\"," + "\"name\":\"" + customerWithdrawalRecord.getRealName() + "\""
                        + "    }," + "\"remark\":\"单笔转账\","
                        + "\"business_params\":\"{\\\"sub_biz_scene\\\":\\\"REDPACKET\\\"}\"" + "  }");
                try {
                    AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
                    log.info("================支付宝红包返回数据：" + response.getBody());
                    if (response.isSuccess()) {
                        customerWithdrawalRecord.setStatus(2);
                        customerWithdrawalRecord.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
                        customerWithdrawalRecord.setChannelOrderId(response.getOrderId());
                    } else {
                        customerWithdrawalRecord.setStatus(3);
                        customerWithdrawalRecord.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
                        if(StringUtils.isNotBlank(response.getSubMsg())) {
                            customerWithdrawalRecord.setRemark(response.getSubMsg());
                        }
                    }

                } catch (Exception e) {
                    WithdrawQueryMQ withdrawQueryMQ = WithdrawQueryMQ.builder().id(customerWithdrawalRecord.getId()).queryTimes(0L).build();
                    withdrawQueryMQ.setTraceId(MDCUtil.getTraceId());
                    messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ,withdrawQueryMQ.getQueryTimes());
                    return;
                }
                customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                if (customerWithdrawalRecord.getStatus() == 3) {
                    walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW,customerWithdrawalRecord.getSettAmt(),customerWithdrawalRecord.getOrderId());

                } else if (customerWithdrawalRecord.getStatus() == 2) {
                    walletService.unfronzenAndDed(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
                }
            } else if (customerWithdrawalRecord.getWithdrawType().eq(WithdrawType.BANKCARD)) {
                try {
                    SysConfig notifyConfig = null;
                    String notifyUrl = null;
                    try {
                        notifyConfig = sysConfigService.getOne(Wraps.<SysConfig>lbQ().eq(SysConfig::getConfigKey, "hcdf_notify_url"));
                        notifyUrl = notifyConfig.getConfigValue();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    String merchId= null;
                    String privateKey = null;
                    SysConfig sysConfig = null;
                    try {
                        sysConfig = sysConfigService.getOne(Wraps.<SysConfig>lbQ().eq(SysConfig::getConfigKey, "hcdf_para_conf"));
                        merchId = sysConfig.getConfigValue();
                        privateKey = sysConfig.getConfigRules();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //customerWithdrawalRecord.setChannelOrderId("bank" + Kits.Date.getyyyyMMddHHmmss() + Kits.Random.getRandom(1000, 10000));
                    //customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                    hcpayService.daifu(DaifuDto.builder()
                            .amount(customerWithdrawalRecord.getTransAmount())
                            .cardId(customerWithdrawalRecord.getWithdrawAccount())
                            .name(customerWithdrawalRecord.getRealName())
                            .idNo(customerWithdrawalRecord.getIdCard())
                            .phone(customerWithdrawalRecord.getMobile())
                            .bankName(customerWithdrawalRecord.getBankBranch())
                            .memo("结算")
                            .notifyUrl(notifyUrl)
                            .orderId(customerWithdrawalRecord.getOrderId()).build(), merchId,privateKey);
                } catch (BizException e) {
                    log.info(e.toString());
                }
                WithdrawQueryMQ withdrawQueryMQ = WithdrawQueryMQ.builder().id(customerWithdrawalRecord.getId()).queryTimes(0L).build();
                withdrawQueryMQ.setTraceId(MDCUtil.getTraceId());
                messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ,withdrawQueryMQ.getQueryTimes());
               /* customerWithdrawalRecord = channelService.paybankSubmit(customerWithdrawalRecord);
                //update+解冻 or 扣除处理
                customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                if (customerWithdrawalRecord.getStatus() == 3) {
                    walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.DEFAULT, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());

                }else if(customerWithdrawalRecord.getStatus() == 2){
                    walletService.unfronzenAndDed(customerWithdrawalRecord.getCustomerId(), WalletType.DEFAULT, TransType.WITHDRAW,customerWithdrawalRecord.getSettAmt(),customerWithdrawalRecord.getOrderId());
                }*/
            } else if (customerWithdrawalRecord.getWithdrawType().eq(WithdrawType.WxPAY)) {
                //微信代付处理
                WxpayServiceRp wxpayServiceRp = new WxpayServiceRp();
                try {
                    wxpayServiceRp = wxpayService.daifu(customerWithdrawalRecord.getOrderId(), customerWithdrawalRecord.getTransAmount(), customerWithdrawalRecord.getRealName(), customerWithdrawalRecord.getIdCard());
                } catch (Exception e) {
                    log.info(e.toString());
                    e.printStackTrace();
                }
                if (wxpayServiceRp.getResult_code().equals("0100")) {
                    WithdrawQueryMQ withdrawQueryMQ = WithdrawQueryMQ.builder().id(customerWithdrawalRecord.getId()).queryTimes(0L).build();
                    withdrawQueryMQ.setTraceId(MDCUtil.getTraceId());
                    messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ, withdrawQueryMQ.getQueryTimes());
                } else {
                    log.info("微信代付异常返回:" + JSON.toJSONString(wxpayServiceRp));
                }

            }

        } else if (customerWithdrawalRecord.getVerifyStatus() == 3) {
            //审核不通过
            walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW,customerWithdrawalRecord.getSettAmt(),customerWithdrawalRecord.getOrderId());
            customerWithdrawalRecord.setStatus(3);
            customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
        }
        WithdrawalRecord withdrawalRecord = withdrawalRecordService.getOne(Wraps.<WithdrawalRecord>lbQ().eq(WithdrawalRecord::getOrderNum,customerWithdrawalRecord.getOrderId()));
        withdrawalRecord.setStatus(customerWithdrawalRecord.getStatus());
        withdrawalRecord.setVerifyStatus(customerWithdrawalRecord.getVerifyStatus());
        withdrawalRecordService.updateById(withdrawalRecord);
        log.info("审核结果状态:{} 处理完成", customerWithdrawalRecord.getVerifyStatus());

    }

    @Override
    public void query(WithdrawQueryMQ withdrawQueryMQ) throws BizException {
        CustomerWithdrawalRecord customerWithdrawalRecord = customerWithdrawalRecordService.getById(withdrawQueryMQ.getId());
        if(customerWithdrawalRecord.getWithdrawType().eq(WithdrawType.ALIPAY)){
            //CustomerWithdrawalRecord customerWithdrawalRecordResp = new CustomerWithdrawalRecord();
            // 支付宝转账查询
            try {
                customerWithdrawalRecord = AlipayQuery(customerWithdrawalRecord, withdrawQueryMQ);
            } catch (AlipayApiException e) {
                log.info(e.getErrCode(), "支付宝查询异常:" + e.getErrMsg() + customerWithdrawalRecord.getChannelOrderId());
                e.printStackTrace();
            }
            if (customerWithdrawalRecord.getStatus() == 2 || customerWithdrawalRecord.getStatus() == 3) {
                WithdrawalRecord withdrawalRecord = withdrawalRecordService.getOne(Wraps.<WithdrawalRecord>lbQ().eq(WithdrawalRecord::getOrderNum, customerWithdrawalRecord.getOrderId()));
                withdrawalRecord.setStatus(customerWithdrawalRecord.getStatus());
                withdrawalRecord.setVerifyStatus(customerWithdrawalRecord.getVerifyStatus());
                withdrawalRecord.setRemark(customerWithdrawalRecord.getRemark());
                withdrawalRecordService.updateById(withdrawalRecord);
            }else{
                withdrawQueryMQ.setQueryTimes(withdrawQueryMQ.getQueryTimes() + 1);
                messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ, withdrawQueryMQ.getQueryTimes());
                return;
            }
        } else if (customerWithdrawalRecord.getWithdrawType().eq(WithdrawType.WxPAY)) {
            try {
                customerWithdrawalRecord = WxpayQuery(customerWithdrawalRecord, withdrawQueryMQ);
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (customerWithdrawalRecord.getStatus() == 2 || customerWithdrawalRecord.getStatus() == 3) {
                WithdrawalRecord withdrawalRecord = withdrawalRecordService.getOne(Wraps.<WithdrawalRecord>lbQ().eq(WithdrawalRecord::getOrderNum, customerWithdrawalRecord.getOrderId()));
                withdrawalRecord.setStatus(customerWithdrawalRecord.getStatus());
                withdrawalRecord.setVerifyStatus(customerWithdrawalRecord.getVerifyStatus());
                withdrawalRecordService.updateById(withdrawalRecord);
            } else {
                withdrawQueryMQ.setQueryTimes(withdrawQueryMQ.getQueryTimes() + 1);
                messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ, withdrawQueryMQ.getQueryTimes());
                return;
            }

        }else{
            TransQueryResponseDto transQueryResponseDto = null;
            try {
                SysConfig sysConfig = sysConfigService.getOne(Wraps.<SysConfig>lbQ().eq(SysConfig::getConfigKey, "hcdf_para_conf"));
                transQueryResponseDto = hcpayService.transQuery(TransQueryDto.builder().orderId(customerWithdrawalRecord.getOrderId()).build(), sysConfig.getConfigValue(),sysConfig.getValidateRules());
            } catch (BizException e) {
                if(e.getMessage().equals("交易记录不存在") && withdrawQueryMQ.getQueryTimes().intValue() > 5) {
                    customerWithdrawalRecord.setRemark(e.getMessage());
                    customerWithdrawalRecord.setStatus(3);
                    customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                    walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
                    return ;
                }

            }
            if(transQueryResponseDto == null){
                withdrawQueryMQ.setQueryTimes(withdrawQueryMQ.getQueryTimes() + 1);
                messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ,withdrawQueryMQ.getQueryTimes());
                return;
            }
            if("02".equals(transQueryResponseDto.getOrderStatus())){
                customerWithdrawalRecord.setRemark(transQueryResponseDto.getRespDesc());
                customerWithdrawalRecord.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
                customerWithdrawalRecord.setStatus(2);
                customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                walletService.unfronzenAndDed(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
            }else if("03".equals(transQueryResponseDto.getOrderStatus())){
                customerWithdrawalRecord.setRemark(transQueryResponseDto.getRespDesc());
                customerWithdrawalRecord.setStatus(3);
                customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());

            }else{
                withdrawQueryMQ.setQueryTimes(withdrawQueryMQ.getQueryTimes() + 1);
                messageService.sendAndQueryTimes(AmqpExchange.WITHDRAW_QUERY_MESSAGE, withdrawQueryMQ,withdrawQueryMQ.getQueryTimes());
                return;
            }
            if(customerWithdrawalRecord.getStatus() == 2 || customerWithdrawalRecord.getStatus() ==3 ){
                WithdrawalRecord withdrawalRecord = withdrawalRecordService.getOne(Wraps.<WithdrawalRecord>lbQ().eq(WithdrawalRecord::getOrderNum,customerWithdrawalRecord.getOrderId()));
                withdrawalRecord.setStatus(customerWithdrawalRecord.getStatus());
                withdrawalRecord.setVerifyStatus(customerWithdrawalRecord.getVerifyStatus());
                withdrawalRecordService.updateById(withdrawalRecord);
            }
        }

    }

    public CustomerWithdrawalRecord AlipayQuery(CustomerWithdrawalRecord customerWithdrawalRecord, WithdrawQueryMQ withdrawQueryMQ) throws AlipayApiException {

        SysConfig sysConfig = sysConfigService.getOne(Wraps.<SysConfig>lbQ().eq(SysConfig::getConfigKey, "alipay_df"));
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
        certAlipayRequest.setAppId(sysConfig.getConfigValue());
        certAlipayRequest.setPrivateKey(sysConfig.getValidateRules());
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setCharset("GBK");
        certAlipayRequest.setSignType("RSA2");
        /*certAlipayRequest.setCertPath(sysConfig.getConfigRules());
        certAlipayRequest.setAlipayPublicCertPath("//home//aliCert//alipayCertPublicKey_RSA2.crt");
        certAlipayRequest.setRootCertPath("//home//aliCert//alipayRootCert.crt");*/
        certAlipayRequest.setCertPath("/usr/local/app/appCertPublicKey_" + sysConfig.getConfigValue() + ".crt");
        certAlipayRequest.setAlipayPublicCertPath("/usr/local/app/alipayCertPublicKey_RSA2_" + sysConfig.getConfigValue() + ".crt");
        certAlipayRequest.setRootCertPath("/usr/local/app/alipayRootCert_" + sysConfig.getConfigValue() + ".crt");

        AlipayClient alipayClient = null;
        try {
            alipayClient = new DefaultAlipayClient(certAlipayRequest);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }

        AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest();
        request.setBizContent("{" +
                "\"out_biz_no\":\"" + customerWithdrawalRecord.getChannelOrderId() + "\"," +
                "\"order_id\":\"\"" +
                "  }");
        AlipayFundTransOrderQueryResponse response = alipayClient.certificateExecute(request);
        log.info(JSON.toJSONString(response));
        if (response.isSuccess()) {
            //System.out.println("调用成功");
            if (response.getStatus().equals("SUCCESS")) {
                customerWithdrawalRecord.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
                customerWithdrawalRecord.setStatus(2);
                customerWithdrawalRecord.setRemark("提现成功");
                customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                walletService.unfronzenAndDed(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
            } else if (response.getStatus().equals("FAIL")) {
                customerWithdrawalRecord.setStatus(3);
                customerWithdrawalRecord.setRemark(response.getFailReason());
                customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
                walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
            } else {
                //INIT DEALING UNKNOWN 什么都不做 无 REFUND逻辑处理
            }
        }
        return customerWithdrawalRecord;
    }

    public CustomerWithdrawalRecord WxpayQuery(CustomerWithdrawalRecord customerWithdrawalRecord, WithdrawQueryMQ withdrawQueryMQ) {
        WxpayServiceRp wxpayServiceRp = new WxpayServiceRp();
        try {
            wxpayServiceRp = wxpayService.querydfOrder(customerWithdrawalRecord.getOrderId());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if ("0000".equals(wxpayServiceRp.getResult_code())) {
            customerWithdrawalRecord.setStatus(2);
            customerWithdrawalRecord.setSettDate(SystemClockUtil.getSettDateyyyyMMdd());
            customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
            walletService.unfronzenAndDed(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
        } else if ("0001".equals(wxpayServiceRp.getResult_code())) {
            customerWithdrawalRecord.setRemark(wxpayServiceRp.getResult_msg());
            customerWithdrawalRecord.setStatus(3);
            customerWithdrawalRecordService.updateById(customerWithdrawalRecord);
            walletService.unfronzen(customerWithdrawalRecord.getCustomerId(), WalletType.BALANCE, TransType.WITHDRAW, customerWithdrawalRecord.getSettAmt(), customerWithdrawalRecord.getOrderId());
        } else {
            //INIT DEALING UNKNOWN 什么都不做
        }
        return customerWithdrawalRecord;
    }

}
